<template>
  <el-page-header title="企业门户管理" content="首页" icon="" />
  <el-card class="box-card">
    <el-row>
      <el-col :span="4">
        <el-avatar :size="100" :src="avatarUrl" />
      </el-col>
      <el-col :span="20">
        <h3 style="line-height: 100px">
          欢迎{{ store.state.userInfo.username }}回来，{{ welcomeText }}
        </h3>
      </el-col>
    </el-row>
  </el-card>
  <el-card class="box-card">
    <template #header>
      <div class="card-header">
        <span style="font-size: 25px;">公司产品</span>
      </div>
    </template>
    <el-carousel :interval="4000" type="card" height="400px">
      <el-carousel-item v-for="item in loopList" :key="item._id">
        <div :style="{backgroundImage:`url(http://203.6.239.220:3000${item.cover})`,backgroundSize:'cover'}" style="height: 100%;">
          <h3 text="2xl" justify="center">{{ item.title }}</h3>
        </div>
      </el-carousel-item>
    </el-carousel>
  </el-card>
</template>

<script setup>
import { computed, ref, onMounted } from "vue";
import { useStore } from "vuex";
import axios from 'axios'

const store = useStore();

const avatarUrl = computed(() =>
  store.state.userInfo.avatar
    ? "http://203.6.239.220:3000" + store.state.userInfo.avatar
    : `https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png`
);
const welcomeText = computed(() =>
  new Date().getHours < 12 ? "要开心每一天！" : "喝杯咖啡提提神吧！"
);

const loopList = ref([])
const getData = async () => {
  const res = await axios.get('/adminapi/product/list')
  loopList.value = res.data.data
}
onMounted(() => {
  getData()
})
</script>

<style lang="scss" scoped>
.box-card {
  margin-top: 50px;
}

.el-carousel__item h3 {
  color: #475669;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>
